package com.easy.framework.web.base;

import com.easy.framework.common.utils.StringUtil;
import com.easy.framework.common.utils.date.DateUtils;
import com.easy.framework.security.model.LoginUser;
import com.easy.framework.security.utils.SecurityUtils;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;

import java.beans.PropertyEditorSupport;
import java.util.Date;

/**
 * 控制器基类，提供公共功能
 * @author Easy
 */
public class BaseController {

    /**
     * 日期格式绑定
     */
    @InitBinder
    public void initBinder(WebDataBinder binder) {
        binder.registerCustomEditor(Date.class, new PropertyEditorSupport() {
            @Override
            public void setAsText(String text) {
                setValue(DateUtils.parseDate(text));
            }
        });
    }

    /**
     * 页面跳转
     */
    public String redirect(String url) {
        return StringUtil.format("redirect:{}", url);
    }

}
